ABAP Select data from SAP table /PM0/ABDEBTSDT 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 /PM0/ABDEBTSDT 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 /PM0/ABDEBTSDT. 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 /PM0/ABDEBTSDT 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_/PM0/ABDEBTSDT TYPE STANDARD TABLE OF /PM0/ABDEBTSDT,
      WA_/PM0/ABDEBTSDT TYPE /PM0/ABDEBTSDT,
      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: </PM0/ABDEBTSDT> TYPE /PM0/ABDEBTSDT.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/PM0/ABDEBTSDT.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PM0/ABDEBTSDT
  INTO TABLE IT_/PM0/ABDEBTSDT.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PM0/ABDEBTSDT
*  INTO TABLE @DATA(IT_/PM0/ABDEBTSDT2).
*--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_/PM0/ABDEBTSDT INDEX 1 INTO DATA(WA_/PM0/ABDEBTSDT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PM0/ABDEBTSDT ASSIGNING </PM0/ABDEBTSDT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PM0/ABDEBTSDT>-BTSDATE = 1.
</PM0/ABDEBTSDT>-CLIENT = 1.
</PM0/ABDEBTSDT>-BTSDATE_ID = 1.
</PM0/ABDEBTSDT>-POLICY_ID = 1.
</PM0/ABDEBTSDT>-PPDPAC_ID = 1.
ENDLOOP.

LOOP AT IT_/PM0/ABDEBTSDT INTO WA_/PM0/ABDEBTSDT.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PM0/ABDEBTSDT-POLICYPRODUCT_ID, sy-vline,
WA_/PM0/ABDEBTSDT-COVPAC_ID, sy-vline,
WA_/PM0/ABDEBTSDT-COVERAGE_ID, sy-vline,
WA_/PM0/ABDEBTSDT-COVCPCO_ID, sy-vline,
WA_/PM0/ABDEBTSDT-BTSDATE_DT, sy-vline,
WA_/PM0/ABDEBTSDT-VERSION_ID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PM0/ABDEBTSDT 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_/PM0/ABDEBTSDT 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_/PM0/ABDEBTSDT INTO WA_/PM0/ABDEBTSDT. *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.

*Conversion exit ALPHA, internal->external for field SENDER_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABDEBTSDT-SENDER_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABDEBTSDT-SENDER_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field POLICYNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABDEBTSDT-POLICYNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABDEBTSDT-POLICYNR_TT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field APPLNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABDEBTSDT-APPLNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABDEBTSDT-APPLNR_TT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field COVERAGENR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABDEBTSDT-COVERAGENR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABDEBTSDT-COVERAGENR_TT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field MPOLICY_NR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABDEBTSDT-MPOLICY_NR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABDEBTSDT-MPOLICY_NR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/PM0/ABDEBTSDT_STR,
BTSDATE TYPE STRING,
CLIENT TYPE STRING,
BTSDATE_ID TYPE STRING,
POLICY_ID TYPE STRING,
PPDPAC_ID TYPE STRING,
POLICYPRODUCT_ID TYPE STRING,
COVPAC_ID TYPE STRING,
COVERAGE_ID TYPE STRING,
COVCPCO_ID TYPE STRING,
BTSDATE_DT TYPE STRING,
VERSION_ID TYPE STRING,
BTSMULT_ID TYPE STRING,
BTSAPPL_ID TYPE STRING,
RELEASE_DT TYPE STRING,
BTX_ID TYPE STRING,
UPDATETYPE_ID TYPE STRING,
FINECTRL_ID TYPE STRING,
STATUS_CD TYPE STRING,
STATUS_DT TYPE STRING,
MOD_TS TYPE STRING,
MODNAME_TT TYPE STRING,
SENDER_ID TYPE STRING,
CDLOCK_CON_ID TYPE STRING,
ORIG_CON_ID TYPE STRING,
BPN_CON_ID TYPE STRING,
BPV_CON_ID TYPE STRING,
BPVPOS_CON_ID TYPE STRING,
BTX_CON_ID TYPE STRING,
CHARGE_CON_ID TYPE STRING,
TAX_CON_ID TYPE STRING,
COMDIFF_CON_ID TYPE STRING,
CANC_CON_ID TYPE STRING,
RUN_ID TYPE STRING,
PRELL_STATUS TYPE STRING,
CHGREASON_CD TYPE STRING,
OTHCHGREASON_TT TYPE STRING,
CANCJOURNAL_ID TYPE STRING,
BTSDTTYPE_CD TYPE STRING,
APPL_DT TYPE STRING,
APPLIN_DT TYPE STRING,
EXECJOURNALNO_ID TYPE STRING,
SUPPRESS_PREDATE_ERROR_FG TYPE STRING,
DUMMY TYPE STRING,
PPD_ID_PRED TYPE STRING,
CANCORDERNO_ID TYPE STRING,
POLICYNR_TT TYPE STRING,
APPLNR_TT TYPE STRING,
COVERAGENR_TT TYPE STRING,
MPOLICY_NR TYPE STRING,
EXTERNAL_RUN_ID TYPE STRING,
STATUS_TT TYPE STRING,
STATUS_LED TYPE STRING,
BTSDTID_TT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PM0/ABDEBTSDT_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_/PM0/ABDEBTSDT_STR-BTSDATE sy-vline
WA_/PM0/ABDEBTSDT_STR-CLIENT sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSDATE_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-POLICY_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-PPDPAC_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-POLICYPRODUCT_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-COVPAC_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-COVERAGE_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-COVCPCO_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSDATE_DT sy-vline
WA_/PM0/ABDEBTSDT_STR-VERSION_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSMULT_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSAPPL_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-RELEASE_DT sy-vline
WA_/PM0/ABDEBTSDT_STR-BTX_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-UPDATETYPE_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-FINECTRL_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-STATUS_CD sy-vline
WA_/PM0/ABDEBTSDT_STR-STATUS_DT sy-vline
WA_/PM0/ABDEBTSDT_STR-MOD_TS sy-vline
WA_/PM0/ABDEBTSDT_STR-MODNAME_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-SENDER_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-CDLOCK_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-ORIG_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BPN_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BPV_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BPVPOS_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BTX_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-CHARGE_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-TAX_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-COMDIFF_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-CANC_CON_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-RUN_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-PRELL_STATUS sy-vline
WA_/PM0/ABDEBTSDT_STR-CHGREASON_CD sy-vline
WA_/PM0/ABDEBTSDT_STR-OTHCHGREASON_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-CANCJOURNAL_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSDTTYPE_CD sy-vline
WA_/PM0/ABDEBTSDT_STR-APPL_DT sy-vline
WA_/PM0/ABDEBTSDT_STR-APPLIN_DT sy-vline
WA_/PM0/ABDEBTSDT_STR-EXECJOURNALNO_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-SUPPRESS_PREDATE_ERROR_FG sy-vline
WA_/PM0/ABDEBTSDT_STR-DUMMY sy-vline
WA_/PM0/ABDEBTSDT_STR-PPD_ID_PRED sy-vline
WA_/PM0/ABDEBTSDT_STR-CANCORDERNO_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-POLICYNR_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-APPLNR_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-COVERAGENR_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-MPOLICY_NR sy-vline
WA_/PM0/ABDEBTSDT_STR-EXTERNAL_RUN_ID sy-vline
WA_/PM0/ABDEBTSDT_STR-STATUS_TT sy-vline
WA_/PM0/ABDEBTSDT_STR-STATUS_LED sy-vline
WA_/PM0/ABDEBTSDT_STR-BTSDTID_TT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.