Skip to content

Instantly share code, notes, and snippets.

View hapejot's full-sized avatar

Peter Jaeckel hapejot

View GitHub Profile
@hapejot
hapejot / read.rs
Created March 30, 2024 20:10
Read file into String
use std::fs;
fn main() {
let s = fs::read_to_string("address.txt").unwrap();
}
@hapejot
hapejot / commands.rs
Created October 1, 2023 12:22
Rust Clap Examples
use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Optional name to operate on
name: Option<String>,
@hapejot
hapejot / fcat.abap
Created September 6, 2023 05:35
Generate Field Catalog for ALV Grid
TRY.
cl_salv_table=>factory( IMPORTING
r_salv_table = DATA(salv_table)
CHANGING
t_table = mt_data ).
mt_fields = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = salv_table->get_columns( ) " ALV Filter
r_aggregations = salv_table->get_aggregations( ) ). " ALV Aggregations
REPORT SADL_ALV_IDA_TEST_CDS_VIEW.
parameters : p_cds AS CHECKBOX DEFAULT abap_true.
parameters : p_set_c as checkbox.
end-of-selection.
cl_fpm_ida_test_data_generator=>generate_data_set_demo( ).
if p_cds eq abap_true.
data(alv) = cl_salv_gui_table_ida=>CREATE_FOR_CDS_VIEW( IV_CDS_VIEW_NAME = 'SFPM_IDA_TEST_CDS_EVENT' ).
@hapejot
hapejot / yrs_zip
Created May 13, 2022 15:35
Creating a ZIP File from within ABAP
**Please use the pattern Z_BC_PROGRAM_HEAD to create the program head**
REPORT yrs_zip.
DATA(z) = NEW cl_abap_zip( ).
DATA(d) = cl_bcs_convert=>string_to_xstring(
iv_string = |Hallo zusammen\n| " Input data
).
z->add(
@hapejot
hapejot / read-file.py
Last active January 21, 2022 12:16
Write JSON to file
with open("products.json", "r") as read_file:
x = read_file.read()
print(x)
@hapejot
hapejot / group_by.abap
Last active March 21, 2022 14:36
ABAP GROUP
LOOP AT demo INTO DATA(address)
GROUP BY ( city = address-city count = GROUP SIZE )
INTO DATA(city_group).
* APPEND value #( city = city-city count = city-count ) TO result.
APPEND city_group TO result.
ENDLOOP.
result = VALUE #( FOR GROUPS city_group OF address IN demo
GROUP BY ( city = address-city
count = GROUP SIZE )
void *iter = NULL;
struct fy_node_pair *n;
while( ( n = fy_node_mapping_iterate( mapping, &iter ) ) )
{
const char *key = fy_node_get_scalar0( fy_node_pair_key( n ) );
struct fy_node *value = fy_node_pair_key( n );
}
char *path = create_config_name( name );
struct fy_document * doc = fy_document_build_from_file( NULL, path );
@hapejot
hapejot / create_config_name.c
Created December 11, 2021 22:34
build name of a config file in home directory
char *create_config_name( const char *name )
{
char *p1 = getenv( "HOME" );
char *p2 = "/.";
int len = strlen( p1 ) + strlen( p2 ) + strlen( name ) + 1;
char *p3 = malloc( len );
assert( p3 );
strcpy( p3, p1 );
strcat( p3, p2 );
strcat( p3, name );