Issue: While loading PO texts in the Material Master from a flat file, the long texts do not automatically wrap into a meaningful sentence. To address this, you can use a Utility Program to Auto Format the Texts into Meaningful Sentence, ensuring that the text is properly structured and readable within the system.
Business Need: Our Client’s lord information group thought of the above issue and we were attempting to track down an answer regarding how to make the message shorten at the perfect locations so the significance of the sentence stays in salvageable shape.
Wondering for no specific reason, I began taking a gander at different standard projects and repaired the standard projects, to sort out how the SAP does it so neatly.
The arrangement was directly in front of us. T-Code SO10 (standard text) does it extremely basic and straight.
The message transfer from a level record is impeccably wrapped and shortened at proper spots to keep the words and the sentence overall significant.
Investigation: Began troubleshooting SO10 t-code starting here, to sort out how the record is wrapped by SAP. Go to t-code SO10 and raise a ruckus around town button.
Note – The info document isn’t designed in any way.
Raise a ruckus around town from Text menu to import a text document.
Pick ASCII.The default Code Page utilized by SAP is ‘4110’.
All the Code Pages in SAP can be tracked down in table TCP00 (SAP code page list).
See, SAP auto organizes the brought messages into significant sentences without breaking the work in the center.
The inference from the above Analysis:
1. Read the file using the below FM.
SAP uses FM ‘WS_FILENAME_GET’ to read the file.
CALL FUNCTION 'WS_FILENAME_GET' EXPORTING def_filename = pa_file mask = ',*.txt.' mode = 'O' title = 'Upload File'(078) IMPORTING filename = pa_file EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5.
Step 2: FM to read the file.
SAP involves FM ‘IMPORT_TEXT’ in ASCII design with code page 4110. The table itf_lines will consequently have the start of the passage (marker ‘/’). This is the key FM which designs the long message into a significant sentence.
* -- Import the file contents to the internal table !!! CALL FUNCTION 'IMPORT_TEXT' EXPORTING codepage = c_codepage file = pa_file format_type = c_ascii word_langu = sy-langu TABLES itf_lines = gt_lines[] EXCEPTIONS file_open_error = 1 file_read_error = 2 upload_error = 3 no_contents = 4 OTHERS = 5.
Keep in mind, we want to send the message to FM SAVE_TEXT. However, LINES table of SAVE_TEXT has a length of 132 characters. In the event that your longtext is more noteworthy than 132 person, it would be hard to accurately break the sentence. Accordingly, utilizing this FM IMPORT_TEXT is exceptionally useful. It consequently breaks the information longtext from document to great sentence and it is fit to be passed to SAVE_TEXT to transfer to our ideal objective.
Note: Ensure the code page is 4110 and is ASCII design.
On the off chance that you use GUI_UPLOAD rather than the above FM, you want to compose your own astute rationale to break the word at the ideal locations and keep it significant. Check this model screen capture beneath where a long text is in li_tab as an extremely lengthy string and we don’t have the foggiest idea how to pass right lines to SAVE_TEXT.
The issue with GUI_UPLOAD is that it isn’t not difficult to break the sentence accurately utilizing some custom rationale. We can’t shorten the in the middle between. So the above FM IMPORT_TEXT is extremely helpful in breaking one long string into different lines of significant sentences.
Q: How to Identify PO text for different material in the file.
Ans: SAP automatically puts ‘/’ for every new paragraph. So every material PO text is separated by ‘/’, i.e. tdformat = ‘/’ (in itf_lines of IMPORT_TEXT).
Also Read – Playing Sherlock Holmes to detect CONVT_CODEPAGE runtime error mystery
Sample Program Developed to simulate the SAP behavior
Selection screen:
CONSTANTS : c_codepage TYPE tcp02-cpcodepage VALUE '4110', c_ascii(5) TYPE c VALUE 'ASCII'. * -- Types declaration TYPES : BEGIN OF gts_err, matnr TYPE matnr, error TYPE bapi_msg, END OF gts_err. * -- Data declarations !!! DATA : gt_lines TYPE TABLE OF tline, gs_line LIKE LINE OF gt_lines, gs_lines LIKE LINE OF gt_lines. DATA : gs_header LIKE thead, gv_matnr TYPE matnr_d, gv_name TYPE tdobname. DATA: gt_lines_save TYPE STANDARD TABLE OF tline, gs_lines_save LIKE LINE OF gt_lines_save. DATA: gt_err TYPE TABLE OF gts_err, gs_err LIKE LINE OF gt_err, gr_message TYPE REF TO cx_salv_msg. *-- REFERENCE definitions * DATA gx_alv TYPE REF TO cl_salv_table. * -- Selection screen.. !!! SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: pa_file LIKE rlgrap-filename OBLIGATORY . SELECTION-SCREEN END OF BLOCK b1. * -- At Selection screen AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING def_filename = pa_file mask = ',*.txt.' mode = 'O' title = 'Upload File'(078) IMPORTING filename = pa_file EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. INITIALIZATION. *Program level Authorization check. CALL FUNCTION 'AUTHORITY_CHECK_TCODE' EXPORTING tcode = 'ZMM_XXX' EXCEPTIONS ok = 0 not_ok = 2 OTHERS = 3. IF sy-subrc NE 0. MESSAGE s000(zs) WITH text-014 DISPLAY LIKE 'E'. LEAVE PROGRAM. ENDIF. START-OF-SELECTION. * -- Read the file contents on the internal table !!! CALL FUNCTION 'IMPORT_TEXT' EXPORTING codepage = c_codepage " 4110 file = pa_file format_type = c_ascii word_langu = sy-langu TABLES itf_lines = gt_lines[] EXCEPTIONS file_open_error = 1 file_read_error = 2 upload_error = 3 no_contents = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE e000(zm) WITH text-err DISPLAY LIKE 'I'. ENDIF. DATA lx_columns TYPE REF TO cl_salv_columns_table. * -- Process the data for final output. gs_header-tdobject = 'MATERIAL'. gs_header-tdid = 'BEST'. gs_header-tdspras = sy-langu. LOOP AT gt_lines INTO gs_lines. REPLACE ALL OCCURRENCES OF '"' IN gs_lines-tdline WITH space. READ TABLE gt_lines INTO gs_line INDEX sy-tabix + 1 . IF gs_lines-tdformat = '/' . " Begin of new record !!! CLEAR gv_matnr. SPLIT gs_lines-tdline AT '~~' INTO gv_matnr gs_lines-tdline. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = gv_matnr IMPORTING output = gv_matnr EXCEPTIONS OTHERS = 1. CLEAR gv_name. gs_header-tdname = gv_matnr. gs_lines_save = gs_lines. APPEND gs_lines_save TO gt_lines_save. CLEAR gs_lines_save. ELSE. gs_lines_save = gs_lines. APPEND gs_lines_save TO gt_lines_save. CLEAR gs_lines_save. ENDIF. IF gs_line-tdformat EQ '/'. CALL FUNCTION 'SAVE_TEXT' EXPORTING client = sy-mandt header = gs_header savemode_direct = 'X' IMPORTING newheader = gs_header TABLES lines = gt_lines_save[] EXCEPTIONS id = 1 language = 2 name = 3 object = 4 OTHERS = 5. IF sy-subrc <> 0. gs_err-matnr = gv_matnr. gs_err-error = text-upr. APPEND gs_err TO gt_err. ELSE. gs_err-matnr = gv_matnr. gs_err-error = text-ups. APPEND gs_err TO gt_err. ENDIF. CLEAR gs_err. REFRESH gt_lines_save[]. ENDIF. ENDLOOP. ** -- Do it for last record. CALL FUNCTION 'SAVE_TEXT' EXPORTING client = sy-mandt header = gs_header savemode_direct = 'X' IMPORTING newheader = gs_header TABLES lines = gt_lines_save[] EXCEPTIONS id = 1 language = 2 name = 3 object = 4 OTHERS = 5. IF sy-subrc <> 0. gs_err-matnr = gv_matnr. gs_err-error = text-upr. APPEND gs_err TO gt_err. ELSE. gs_err-matnr = gv_matnr. gs_err-error = text-ups. APPEND gs_err TO gt_err. ENDIF. CLEAR gs_err. REFRESH gt_lines_save[].. IF gt_err[] IS NOT INITIAL. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = gx_alv CHANGING t_table = gt_err ). CATCH cx_salv_msg INTO gr_message. ENDTRY. lx_columns = gx_alv->get_columns( ). lx_columns->set_optimize( 'X' ). ENDIF. gx_alv->display( ).
The output of the report
Note: For our case, the material number is the principal word in the record and it is isolated by ‘~~’.
Let us validate the PO Text in the Material Master. Go to MM03 -> Purchase Order Text -> Give the Plant -> Hit the Text Editor.
Look the texts move to the following line at whatever point there is space crunch. The importance of the sentence is unblemished. Furthermore, the words are not in the middle of between two lines.
This is just a basic perception. Many of you may already be using SAVE_TEXT to get your text auto-formatted. However, if you are a first-time ABAP, I wanted to show you what your approach should be to tackle any SAP issue. You need to look for the answer in the Standard SAP Solutions. SAP has everything, including a utility program to Auto Format the Texts into Meaningful Sentence. We just need to learn how to troubleshoot at the right locations and figure out how to incorporate them into our custom program.
YOU MAY LIKE THIS
Which SAP module is easy to learn
Optimizing SAP for the Automotive Sector: A Comprehensive Guide