ABAP Select data from SAP table BBPS_ACC_REASSGMT 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 BBPS_ACC_REASSGMT 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 BBPS_ACC_REASSGMT. 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 BBPS_ACC_REASSGMT 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_BBPS_ACC_REASSGMT TYPE STANDARD TABLE OF BBPS_ACC_REASSGMT, WA_BBPS_ACC_REASSGMT TYPE BBPS_ACC_REASSGMT, 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: <BBPS_ACC_REASSGMT> TYPE BBPS_ACC_REASSGMT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BBPS_ACC_REASSGMT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BBPS_ACC_REASSGMT INTO TABLE IT_BBPS_ACC_REASSGMT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BBPS_ACC_REASSGMT * INTO TABLE @DATA(IT_BBPS_ACC_REASSGMT2). *--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_BBPS_ACC_REASSGMT INDEX 1 INTO DATA(WA_BBPS_ACC_REASSGMT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BBPS_ACC_REASSGMT ASSIGNING <BBPS_ACC_REASSGMT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BBPS_ACC_REASSGMT>-OBJID = 1.
<BBPS_ACC_REASSGMT>-NUMBER_EXT = 1.
<BBPS_ACC_REASSGMT>-REFBT_DOC_CAT = 1.
<BBPS_ACC_REASSGMT>-RFKNT_ACC_LN = 1.
<BBPS_ACC_REASSGMT>-RFETE_SERV_LN = 1.
ENDLOOP. LOOP AT IT_BBPS_ACC_REASSGMT INTO WA_BBPS_ACC_REASSGMT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BBPS_ACC_REASSGMT-OBJID_SRM, sy-vline,
WA_BBPS_ACC_REASSGMT-NUMBER_INT, sy-vline,
WA_BBPS_ACC_REASSGMT-SFIPOS, sy-vline,
WA_BBPS_ACC_REASSGMT-SFIPEX, sy-vline,
WA_BBPS_ACC_REASSGMT-SFISTL, sy-vline,
WA_BBPS_ACC_REASSGMT-SFONDS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BBPS_ACC_REASSGMT 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_BBPS_ACC_REASSGMT 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_BBPS_ACC_REASSGMT INTO WA_BBPS_ACC_REASSGMT. *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 OBJID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-OBJID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-OBJID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OBJID_SRM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-OBJID_SRM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-OBJID_SRM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIS, internal->external for field SFIPOS CALL FUNCTION 'CONVERSION_EXIT_FMCIS_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-SFIPOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-SFIPOS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field SFIPEX CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-SFIPEX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-SFIPEX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SHKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-SHKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-SHKONT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SGRANT_NBR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-SGRANT_NBR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-SGRANT_NBR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIS, internal->external for field RFIPOS CALL FUNCTION 'CONVERSION_EXIT_FMCIS_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-RFIPOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-RFIPOS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit FMCIL, internal->external for field RFIPEX CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-RFIPEX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-RFIPEX.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RHKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-RHKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-RHKONT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RGRANT_NBR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_ACC_REASSGMT-RGRANT_NBR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_ACC_REASSGMT-RGRANT_NBR.
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_BBPS_ACC_REASSGMT_STR,
OBJID TYPE STRING,
NUMBER_EXT TYPE STRING,
REFBT_DOC_CAT TYPE STRING,
RFKNT_ACC_LN TYPE STRING,
RFETE_SERV_LN TYPE STRING,
OBJID_SRM TYPE STRING,
NUMBER_INT TYPE STRING,
SFIPOS TYPE STRING,
SFIPEX TYPE STRING,
SFISTL TYPE STRING,
SFONDS TYPE STRING,
SFAREA TYPE STRING,
SHKONT TYPE STRING,
SOBJNRZ TYPE STRING,
SMEASURE TYPE STRING,
SGRANT_NBR TYPE STRING,
SBUDGET_PD TYPE STRING,
RFIPOS TYPE STRING,
RFIPEX TYPE STRING,
RFISTL TYPE STRING,
RFONDS TYPE STRING,
RFAREA TYPE STRING,
RHKONT TYPE STRING,
ROBJNRZ TYPE STRING,
RMEASURE TYPE STRING,
RGRANT_NBR TYPE STRING,
RBUDGET_PD TYPE STRING,END OF T_EKKO_STR. DATA: WA_BBPS_ACC_REASSGMT_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_BBPS_ACC_REASSGMT_STR-OBJID sy-vline
WA_BBPS_ACC_REASSGMT_STR-NUMBER_EXT sy-vline
WA_BBPS_ACC_REASSGMT_STR-REFBT_DOC_CAT sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFKNT_ACC_LN sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFETE_SERV_LN sy-vline
WA_BBPS_ACC_REASSGMT_STR-OBJID_SRM sy-vline
WA_BBPS_ACC_REASSGMT_STR-NUMBER_INT sy-vline
WA_BBPS_ACC_REASSGMT_STR-SFIPOS sy-vline
WA_BBPS_ACC_REASSGMT_STR-SFIPEX sy-vline
WA_BBPS_ACC_REASSGMT_STR-SFISTL sy-vline
WA_BBPS_ACC_REASSGMT_STR-SFONDS sy-vline
WA_BBPS_ACC_REASSGMT_STR-SFAREA sy-vline
WA_BBPS_ACC_REASSGMT_STR-SHKONT sy-vline
WA_BBPS_ACC_REASSGMT_STR-SOBJNRZ sy-vline
WA_BBPS_ACC_REASSGMT_STR-SMEASURE sy-vline
WA_BBPS_ACC_REASSGMT_STR-SGRANT_NBR sy-vline
WA_BBPS_ACC_REASSGMT_STR-SBUDGET_PD sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFIPOS sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFIPEX sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFISTL sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFONDS sy-vline
WA_BBPS_ACC_REASSGMT_STR-RFAREA sy-vline
WA_BBPS_ACC_REASSGMT_STR-RHKONT sy-vline
WA_BBPS_ACC_REASSGMT_STR-ROBJNRZ sy-vline
WA_BBPS_ACC_REASSGMT_STR-RMEASURE sy-vline
WA_BBPS_ACC_REASSGMT_STR-RGRANT_NBR sy-vline
WA_BBPS_ACC_REASSGMT_STR-RBUDGET_PD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.