> 17.10 | AT^SPBG Display phonebook entries in alphabetical order

> AT^SPBG sorts the entries of the current phonebook in alphabetical order by name (the first six characters matter). The sort order is described in Section 17.1, Sort Order for Phonebooks.
> There are two ways to use AT^SPBG:

> • | If the optional parameter <RealLocReq> equals 0 or is omitted the sorted entries will be sequentially numbered. As these numbers are not identical with the location numbers stored in the various phonebooks AT^SPBG can be used for reading only. For example, it helps you find entries starting with matching characters. Do not use the serial numbers to dial out or modify entries.

> • | If parameter <RealLocReq>=1 is given by the write command, the response parameter <location> additionally appended to each entry indicates the actual location number. This number can be used for editing with AT+CPBW or dialing with ATD><mem><n>. The first index number of each entry is only the serial number of the sorted list.

> Before using the AT^SPBG write command it is recommended to query the number of records currently stored in the active phonebook (refer to test command parameter <used>). The test command also includes the parameters <nlength> and <tlength>. Note that if SIM storage is selected the length may not be available. If storage does not offer format information, the format list should be empty parenthesises.
> Syntax

> Test Command AT^SPBG=?
> Response(s)
> ^SPBG: (1-<used>), <nlength>, <tlength>
> OK
> ERROR
> +CME ERROR

> Write Command AT^SPBG=<index1>[, <index2>][, <RealLocReq>]
> Response(s)
> [^SPBG: <index1>, <number>, <type>, <text>[, <location>]]
> [^SPBG: <index2>, <number>, <type>, <text>[, <location>]]
> OK
> ERROR
> +CME ERROR

> Reference(s) |  | PIN |  | ASC0 | ASC1 | USB | MUX1 | MUX2 | MUX3 |  |  | Charge | Q | Last
> SIEMENS |  | + |  | + | + | + | + | + | + |  |  | - | + | -

> Parameter Description

> <index1>(num)

> First index number in the sorted list where to start reading. The supported range is given in the test command response.
> If <index 1> exceeds the upper bound <used>, "+CME ERROR: "invalid index" will be returned.

> <index2>(num)

> Last index number in the sorted list where to stop reading. The supported range is given in the test command response.
> If <index2> is not given via write command, only the entry located at <index1> will be displayed.
> If both <index1> and <index2> are in the range indicated by the test command parameter <used>, the list of entries will be output and terminated with OK.
> If <index2> exceeds the range indicated by the test command parameter <used>, the list of entries will be output but terminated with a "+CME ERROR: "invalid index".
> Note: The maximum value of <index2> is 255, regardless of the phonebook type and its range indicated by the parameter <used>. If a value greater than 255 is used the query returns no phonebook records, and only "+CME ERROR: invalid index" is shown.

> <RealLocReq>(num)

> Is a display of the "real" <location> of the entry required?
> [0]
> Do not show an entry's "real" location number. Parameter <location> will not be displayed.
> 1
> Show the "real" location number as parameter <location> at the end of each entry.

> <number>(str)

> String type phone number in format specified by <type>.
> The number parameter may be an empty string.

> <type>(num)

> Type of address octet, which defines the used type of number (ton) and the numbering plan identification (npi).
> Please consider that for types other than 129 or 145 dialing from phonebook with ATD><mem><n> is, depending on the network, not always possible (refer to GSM 04.08 subclause 10.5.4.7 for details). See also <type> of AT+CPBW.
> Possible values are:
> 145
> Dialing string <number> includes international access code character '+'
> 161
> National number. Network support of this type is optional.
> 209
> Dialing string <number> has been saved as ASCII string and includes non-digit characters other than "*", "#" or "+". Note that phonebook entries saved with this type cannot be dialed.
> 255
> Dialing string <number> is a command to control a Supplementary Service, i.e. "*", "#" codes are contained. Network support of this type is optional.
> 129
> Otherwise

> <text>(str)(+CSCS)

> Text assigned to the phone number. The maximum length for this parameter is given in test command response <tlength>.

> <used>(num)

> Value indicating the number of used locations in selected memory storage.

> <location>(num)

> The location within phonebook memory at which the corresponding entry is located.
> This location may be used for other commands (e.g. AT+CPBR or ATD><mem><n>)

> <nlength>(num)

> Maximum length of phone number for "normal" locations. Depending on the storage, a limited number of locations with extended memory is available per phonebook. Please refer to AT command AT+CPBW for detail.

> <tlength>(num)

> Maximum length of <text> assigned to the telephone number. The value indicated by the test command is given in octets. If the <text> string is given in GSM characters, each character corresponds to one octet. If the <text> string is given in UCS2, the maximum number of characters depends on the coding scheme used for the alpha field of the SIM according to GSM 11.11, Annex B [26]. In the worst case the number of UCS2 characters is at least one less than half the number of GSM characters.
> Notes

> • | The command can be used for the phonebooks "SM", "FD", "ME" (cf. AT+CPBS).

> • | Users should be aware that when using this AT command quickly after SIM PIN authentication the SIM data may not yet be accessible, resulting in a short delay before the requested AT command response is returned. See Section 23.1, Restricted access to SIM data after SIM PIN authentication for further detail.

> Examples

> EXAMPLE 1 | Using AT^SPBG without <RealLocReq>:

> AT^SPBG=? | First run the AT^SPBG test command to find out the range of entries stored in the current phonebook.
> ^SPBG: (1-33),20,17 | TA returns the range, where 33 is the number of entries stored in the current phonebook.
> AT^SPBG=1,33 | Now, enter the write command. To obtain best results it is recommended to query the full range of entries. TA returns phonebook entries in alphabetical order.
> ^SPBG:1,"+999999",145,"Arthur"
> ^SPBG:2,"+777777",145,"Bill"
> ^SPBG:3,"+888888",145,"Charlie"
> ......................

> The numbers at the beginning of each line are not the memory locations in the phonebook, but only serial numbers assigned to the entries' positions in the alphabetical list.

> EXAMPLE 2 | Using AT^SPBG with <RealLocReq>:

> AT^SPBG=? | First run the AT^SPBG test command to find out the range of entries stored in the current phonebook.
> ^SPBG: (1-33),20,17 | TA returns the range, where 33 is the number of entries stored in the current phonebook.
> AT^SPBG=1,33,1 | Now, enter the write command including parameter <RealLocReq>=1 to get the actual location numbers.
> ^SPBG:1,"+999999",145,"Arthur",27
> ^SPBG:2,"+777777",145,"Bill",6
> ^SPBG:3,"+888888",145,"Charlie",15
> ......................

> The numbers at the end of each line are the memory locations in the phonebook and can be used for dialing or editing phonebook entries:

> AT+CPBR=27 | Read out phonebook location 27.
> +CPBR: 27,"+999999",145,"Arthur" | This entry can be edited with AT+CPBW or used for dialing with ATD><mem><n>.