ABAP Select data from SAP table PS3394 into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP PS3394 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to PS3394. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the PS3394 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_PS3394 TYPE STANDARD TABLE OF PS3394, WA_PS3394 TYPE PS3394, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <PS3394> TYPE PS3394. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS3394. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS3394 INTO TABLE IT_PS3394. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS3394 * INTO TABLE @DATA(IT_PS33942). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_PS3394 INDEX 1 INTO DATA(WA_PS33942). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS3394 ASSIGNING <PS3394>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS3394>-STATUS = 1.
<PS3394>-RELEASE_DATE = 1.
<PS3394>-LANGUAGE = 1.
<PS3394>-EXERCISED_JOB = 1.
<PS3394>-HOURS_WORKED = 1.
ENDLOOP. LOOP AT IT_PS3394 INTO WA_PS3394. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS3394-HOURS_TW_01, sy-vline,
WA_PS3394-HOURS_TW_02, sy-vline,
WA_PS3394-HOURS_TW_03, sy-vline,
WA_PS3394-HOURS_TW_04, sy-vline,
WA_PS3394-HOURS_TW_05, sy-vline,
WA_PS3394-HOURS_TW_06, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS3394 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_PS3394 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_PS3394 INTO WA_PS3394. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PS3394_STR,
STATUS TYPE STRING,
RELEASE_DATE TYPE STRING,
LANGUAGE TYPE STRING,
EXERCISED_JOB TYPE STRING,
HOURS_WORKED TYPE STRING,
HOURS_TW_01 TYPE STRING,
HOURS_TW_02 TYPE STRING,
HOURS_TW_03 TYPE STRING,
HOURS_TW_04 TYPE STRING,
HOURS_TW_05 TYPE STRING,
HOURS_TW_06 TYPE STRING,
HOURS_TW_07 TYPE STRING,
HOURS_TW_08 TYPE STRING,
HOURS_TW_09 TYPE STRING,
HOURS_TW_10 TYPE STRING,
HOURS_TW_11 TYPE STRING,
HOURS_TW_12 TYPE STRING,
HOURS_TW_13 TYPE STRING,
HOURS_TW_14 TYPE STRING,
HOURS_TW_15 TYPE STRING,
HOURS_TW_16 TYPE STRING,
HOURS_TW_17 TYPE STRING,
HOURS_TW_18 TYPE STRING,
HOURS_TW_19 TYPE STRING,
HOURS_TW_20 TYPE STRING,
HOURS_TW_21 TYPE STRING,
HOURS_TW_22 TYPE STRING,
HOURS_TW_23 TYPE STRING,
HOURS_TW_24 TYPE STRING,
HOURS_TW_25 TYPE STRING,
HOURS_TW_26 TYPE STRING,
HOURS_TW_27 TYPE STRING,
HOURS_TW_28 TYPE STRING,
HOURS_TW_29 TYPE STRING,
HOURS_TW_30 TYPE STRING,
HOURS_TW_31 TYPE STRING,
CONTRACT_EXISTS TYPE STRING,
WORK_H_DEF TYPE STRING,
WORK_H_WEEK TYPE STRING,
WP_WEEKLYHOURS TYPE STRING,
WORK_CO_GAV TYPE STRING,
ENH_OFFERED TYPE STRING,
ENH_DAILY TYPE STRING,
ENH_WEEKLY TYPE STRING,
ENH_MONTHLY TYPE STRING,
REASON_REJE TYPE STRING,
WA_AHV_BR_HB TYPE STRING,
WA_AHV_BR_MB TYPE STRING,
NUM_H_FOR_BR TYPE STRING,
WA_AHV_BR_H TYPE STRING,
WA_AHV_BR_M TYPE STRING,
BASE_WAGE TYPE STRING,
COMP_FEAST TYPE STRING,
COMP_HOLIDAY TYPE STRING,
MONTH13_GRATUITY TYPE STRING,
OTHER_WAGE_TEXT TYPE STRING,
OTHER_WAGE TYPE STRING,
MONTH13_DATE TYPE STRING,
MONTH13_PRCT TYPE STRING,
BVG_INSURANCE TYPE STRING,
AHV_INSURANCE TYPE STRING,
BONUS_NUM_C TYPE STRING,
BONUS_NUM_E TYPE STRING,
BONUS_WHY_NT TYPE STRING,
EMPL_FURT_TY TYPE STRING,
EMPL_FURT_DA TYPE STRING,
EMPL_FURT_WH TYPE STRING,
EMPL_FURT_DW TYPE STRING,
EMPL_FURT_TW TYPE STRING,
EMPL_FURT_RE TYPE STRING,
PARTICIP_TYPE TYPE STRING,
EMPLOY_SELF_WAGE TYPE STRING,
EMPL_SELF_MA TYPE STRING,
ISSUER_DATE TYPE STRING,
ISSUER_PLACE TYPE STRING,
ISSUER_PHONE TYPE STRING,
ISSUER_BUR_CODE TYPE STRING,
ISSUER_IND_CO TYPE STRING,
ISSUER_ADDRESS_1 TYPE STRING,
ISSUER_ADDRESS_2 TYPE STRING,
ISSUER_ADDRESS_3 TYPE STRING,
CURRENCY TYPE STRING,
COMP_FEAST_AMT TYPE STRING,
COMP_HOLIDAY_AMT TYPE STRING,
MONTH13_GRA_AMT TYPE STRING,
OTHER_WAGE_AMT TYPE STRING,
MONTH13_DATE_S TYPE STRING,
MONTH13_PRCT2 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS3394_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_PS3394_STR-STATUS sy-vline
WA_PS3394_STR-RELEASE_DATE sy-vline
WA_PS3394_STR-LANGUAGE sy-vline
WA_PS3394_STR-EXERCISED_JOB sy-vline
WA_PS3394_STR-HOURS_WORKED sy-vline
WA_PS3394_STR-HOURS_TW_01 sy-vline
WA_PS3394_STR-HOURS_TW_02 sy-vline
WA_PS3394_STR-HOURS_TW_03 sy-vline
WA_PS3394_STR-HOURS_TW_04 sy-vline
WA_PS3394_STR-HOURS_TW_05 sy-vline
WA_PS3394_STR-HOURS_TW_06 sy-vline
WA_PS3394_STR-HOURS_TW_07 sy-vline
WA_PS3394_STR-HOURS_TW_08 sy-vline
WA_PS3394_STR-HOURS_TW_09 sy-vline
WA_PS3394_STR-HOURS_TW_10 sy-vline
WA_PS3394_STR-HOURS_TW_11 sy-vline
WA_PS3394_STR-HOURS_TW_12 sy-vline
WA_PS3394_STR-HOURS_TW_13 sy-vline
WA_PS3394_STR-HOURS_TW_14 sy-vline
WA_PS3394_STR-HOURS_TW_15 sy-vline
WA_PS3394_STR-HOURS_TW_16 sy-vline
WA_PS3394_STR-HOURS_TW_17 sy-vline
WA_PS3394_STR-HOURS_TW_18 sy-vline
WA_PS3394_STR-HOURS_TW_19 sy-vline
WA_PS3394_STR-HOURS_TW_20 sy-vline
WA_PS3394_STR-HOURS_TW_21 sy-vline
WA_PS3394_STR-HOURS_TW_22 sy-vline
WA_PS3394_STR-HOURS_TW_23 sy-vline
WA_PS3394_STR-HOURS_TW_24 sy-vline
WA_PS3394_STR-HOURS_TW_25 sy-vline
WA_PS3394_STR-HOURS_TW_26 sy-vline
WA_PS3394_STR-HOURS_TW_27 sy-vline
WA_PS3394_STR-HOURS_TW_28 sy-vline
WA_PS3394_STR-HOURS_TW_29 sy-vline
WA_PS3394_STR-HOURS_TW_30 sy-vline
WA_PS3394_STR-HOURS_TW_31 sy-vline
WA_PS3394_STR-CONTRACT_EXISTS sy-vline
WA_PS3394_STR-WORK_H_DEF sy-vline
WA_PS3394_STR-WORK_H_WEEK sy-vline
WA_PS3394_STR-WP_WEEKLYHOURS sy-vline
WA_PS3394_STR-WORK_CO_GAV sy-vline
WA_PS3394_STR-ENH_OFFERED sy-vline
WA_PS3394_STR-ENH_DAILY sy-vline
WA_PS3394_STR-ENH_WEEKLY sy-vline
WA_PS3394_STR-ENH_MONTHLY sy-vline
WA_PS3394_STR-REASON_REJE sy-vline
WA_PS3394_STR-WA_AHV_BR_HB sy-vline
WA_PS3394_STR-WA_AHV_BR_MB sy-vline
WA_PS3394_STR-NUM_H_FOR_BR sy-vline
WA_PS3394_STR-WA_AHV_BR_H sy-vline
WA_PS3394_STR-WA_AHV_BR_M sy-vline
WA_PS3394_STR-BASE_WAGE sy-vline
WA_PS3394_STR-COMP_FEAST sy-vline
WA_PS3394_STR-COMP_HOLIDAY sy-vline
WA_PS3394_STR-MONTH13_GRATUITY sy-vline
WA_PS3394_STR-OTHER_WAGE_TEXT sy-vline
WA_PS3394_STR-OTHER_WAGE sy-vline
WA_PS3394_STR-MONTH13_DATE sy-vline
WA_PS3394_STR-MONTH13_PRCT sy-vline
WA_PS3394_STR-BVG_INSURANCE sy-vline
WA_PS3394_STR-AHV_INSURANCE sy-vline
WA_PS3394_STR-BONUS_NUM_C sy-vline
WA_PS3394_STR-BONUS_NUM_E sy-vline
WA_PS3394_STR-BONUS_WHY_NT sy-vline
WA_PS3394_STR-EMPL_FURT_TY sy-vline
WA_PS3394_STR-EMPL_FURT_DA sy-vline
WA_PS3394_STR-EMPL_FURT_WH sy-vline
WA_PS3394_STR-EMPL_FURT_DW sy-vline
WA_PS3394_STR-EMPL_FURT_TW sy-vline
WA_PS3394_STR-EMPL_FURT_RE sy-vline
WA_PS3394_STR-PARTICIP_TYPE sy-vline
WA_PS3394_STR-EMPLOY_SELF_WAGE sy-vline
WA_PS3394_STR-EMPL_SELF_MA sy-vline
WA_PS3394_STR-ISSUER_DATE sy-vline
WA_PS3394_STR-ISSUER_PLACE sy-vline
WA_PS3394_STR-ISSUER_PHONE sy-vline
WA_PS3394_STR-ISSUER_BUR_CODE sy-vline
WA_PS3394_STR-ISSUER_IND_CO sy-vline
WA_PS3394_STR-ISSUER_ADDRESS_1 sy-vline
WA_PS3394_STR-ISSUER_ADDRESS_2 sy-vline
WA_PS3394_STR-ISSUER_ADDRESS_3 sy-vline
WA_PS3394_STR-CURRENCY sy-vline
WA_PS3394_STR-COMP_FEAST_AMT sy-vline
WA_PS3394_STR-COMP_HOLIDAY_AMT sy-vline
WA_PS3394_STR-MONTH13_GRA_AMT sy-vline
WA_PS3394_STR-OTHER_WAGE_AMT sy-vline
WA_PS3394_STR-MONTH13_DATE_S sy-vline
WA_PS3394_STR-MONTH13_PRCT2 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.