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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PM0/ABEASBTAGRINV ASSIGNING </PM0/ABEASBTAGRINV>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PM0/ABEASBTAGRINV>-OBJVALKIND_CD = 1.
</PM0/ABEASBTAGRINV>-OBJVALUE_AM = 1.
</PM0/ABEASBTAGRINV>-POST_CODE1 = 1.
</PM0/ABEASBTAGRINV>-STREET = 1.
</PM0/ABEASBTAGRINV>-COUNTRY = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PM0/ABEASBTAGRINV-CITY1, sy-vline,
WA_/PM0/ABEASBTAGRINV-HOUSE_NUM1, sy-vline,
WA_/PM0/ABEASBTAGRINV-CUSTOMER_FACE_CI, sy-vline,
WA_/PM0/ABEASBTAGRINV-LATITUDEM_CD, sy-vline,
WA_/PM0/ABEASBTAGRINV-LATITUDES_CD, sy-vline,
WA_/PM0/ABEASBTAGRINV-LATITUDE_CD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PM0/ABEASBTAGRINV 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/ABEASBTAGRINV 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/ABEASBTAGRINV INTO WA_/PM0/ABEASBTAGRINV. *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 PARTNER_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABEASBTAGRINV-PARTNER_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABEASBTAGRINV-PARTNER_ID.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field EXTOBJNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABEASBTAGRINV-EXTOBJNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABEASBTAGRINV-EXTOBJNR_TT.
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/ABEASBTAGRINV_STR,
OBJVALKIND_CD TYPE STRING,
OBJVALUE_AM TYPE STRING,
POST_CODE1 TYPE STRING,
STREET TYPE STRING,
COUNTRY TYPE STRING,
CITY1 TYPE STRING,
HOUSE_NUM1 TYPE STRING,
CUSTOMER_FACE_CI TYPE STRING,
LATITUDEM_CD TYPE STRING,
LATITUDES_CD TYPE STRING,
LATITUDE_CD TYPE STRING,
LONGITUDEM_CD TYPE STRING,
LONGITUDES_CD TYPE STRING,
LONGITUDE_CD TYPE STRING,
OBJVALKIND_TT TYPE STRING,
IOPUFFER_ID TYPE STRING,
/PM0/ABDASUBJCT_OID TYPE STRING,
PARTNER_ID TYPE STRING,
EFFECTIVITY_DT TYPE STRING,
OBJCAT_CD TYPE STRING,
OBJTYP_CD TYPE STRING,
INSOBJNR_TT TYPE STRING,
AWARDREASON_CD TYPE STRING,
UPDATEREQUIRE_FG TYPE STRING,
TYPCHANSTRUK_TT TYPE STRING,
CATCHANSTRUK_TT TYPE STRING,
SUPCHANSTRUK_TT TYPE STRING,
JOURVBO_CD TYPE STRING,
PM_ID TYPE STRING,
CURRENCY_ID TYPE STRING,
INSDECNR_TT TYPE STRING,
OBJPOSNR_TT TYPE STRING,
NOPREMRAISE_FG TYPE STRING,
LOCCHANGE_FG TYPE STRING,
RISKGROUPNR_TT TYPE STRING,
CUSTOMER_PB_CI TYPE STRING,
ADRESSE_TT TYPE STRING,
AWARDREASON_TT TYPE STRING,
COMMENTCOV_TT TYPE STRING,
COMMENTPOLPR_TT TYPE STRING,
COMMENT_TT TYPE STRING,
EXTOBJNR_TT TYPE STRING,
INFLRIDPM2_ID TYPE STRING,
INFLRIDPM2_TT TYPE STRING,
INFLRIDPM_ID TYPE STRING,
INFLRIDPM_TT TYPE STRING,
INSDEC_TT TYPE STRING,
INSOBJ_TT TYPE STRING,
NAME_TT TYPE STRING,
OBJCAT_TT TYPE STRING,
OBJTYP_TT TYPE STRING,
PBSTYP_TT TYPE STRING,
PM_TT TYPE STRING,
SUBJECT_TD TYPE STRING,
SYNCHRONOUS_FG TYPE STRING,
CUSTOMER_TB_CI TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PM0/ABEASBTAGRINV_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/ABEASBTAGRINV_STR-OBJVALKIND_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJVALUE_AM sy-vline
WA_/PM0/ABEASBTAGRINV_STR-POST_CODE1 sy-vline
WA_/PM0/ABEASBTAGRINV_STR-STREET sy-vline
WA_/PM0/ABEASBTAGRINV_STR-COUNTRY sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CITY1 sy-vline
WA_/PM0/ABEASBTAGRINV_STR-HOUSE_NUM1 sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CUSTOMER_FACE_CI sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LATITUDEM_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LATITUDES_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LATITUDE_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LONGITUDEM_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LONGITUDES_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LONGITUDE_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJVALKIND_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-IOPUFFER_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-/PM0/ABDASUBJCT_OID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-PARTNER_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-EFFECTIVITY_DT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJCAT_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJTYP_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INSOBJNR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-AWARDREASON_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-UPDATEREQUIRE_FG sy-vline
WA_/PM0/ABEASBTAGRINV_STR-TYPCHANSTRUK_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CATCHANSTRUK_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-SUPCHANSTRUK_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-JOURVBO_CD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-PM_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CURRENCY_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INSDECNR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJPOSNR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-NOPREMRAISE_FG sy-vline
WA_/PM0/ABEASBTAGRINV_STR-LOCCHANGE_FG sy-vline
WA_/PM0/ABEASBTAGRINV_STR-RISKGROUPNR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CUSTOMER_PB_CI sy-vline
WA_/PM0/ABEASBTAGRINV_STR-ADRESSE_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-AWARDREASON_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-COMMENTCOV_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-COMMENTPOLPR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-COMMENT_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-EXTOBJNR_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INFLRIDPM2_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INFLRIDPM2_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INFLRIDPM_ID sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INFLRIDPM_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INSDEC_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-INSOBJ_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-NAME_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJCAT_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-OBJTYP_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-PBSTYP_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-PM_TT sy-vline
WA_/PM0/ABEASBTAGRINV_STR-SUBJECT_TD sy-vline
WA_/PM0/ABEASBTAGRINV_STR-SYNCHRONOUS_FG sy-vline
WA_/PM0/ABEASBTAGRINV_STR-CUSTOMER_TB_CI sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.